package org.apache.ibatis.demo.plugin;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.util.Properties;

/**
 * @fileName: MyPlugin
 * @author: zengqf3
 * @date: 2021-6-26 16:11
 * @description:
 */
@Intercepts({@Signature(type = Executor.class, method = "query", args = {
  MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class
})})
public class MyPlugin1 implements Interceptor {
  @Override
  public Object intercept(Invocation invocation) throws Throwable {
    System.out.println("Executor--的query方法进行了增强");
    return invocation.proceed();
  }

  //生成一个拦截器对象，丢到拦截器链中
  @Override
  public Object plugin(Object target) {
    System.out.println("Executor--将要包装的目标对象" + target);
    return Plugin.wrap(target, this);
  }

  @Override
  public void setProperties(Properties properties) {
    System.out.println("Executor--配置的初始化参数" + properties);
  }
}
